Skip to content

Commit

Permalink
support NO_COLOR #10
Browse files Browse the repository at this point in the history
  • Loading branch information
laktak committed Jun 30, 2023
1 parent 7214723 commit 8baf277
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ Alternatively you can pipe the output from rsync to rsyncy (in which case you ne
$ rsync -a --info=progress2 -hv FROM/ TO | rsyncy
```

At the moment `rsyncy` itself has no options and only supports my preferred way of viewing rsync progress.
At the moment `rsyncy` itself has only one option, you can turn off colors via the `NO_COLOR=1` environment variable.



## lf support

Expand Down
24 changes: 20 additions & 4 deletions rsyncy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@


class CLI:
NO_COLOR = os.environ.get("NO_COLOR", "")

class style:
reset = "\033[0m"
bold = "\033[01m"
Expand All @@ -29,6 +31,8 @@ def clear_line(opt=0):
return "\033[" + str(opt) + "K"

def get_col_bits():
if CLI.NO_COLOR:
return 1
c, t = os.environ.get("COLORTERM", ""), os.environ.get("TERM", "")
if c in ["truecolor", "24bit"]:
return 24
Expand All @@ -41,18 +45,30 @@ def get_col_bits():
def fg4(col):
# black=0,red=1,green=2,orange=3,blue=4,purple=5,cyan=6,lightgrey=7
# darkgrey=8,lightred=9,lightgreen=10,yellow=11,lightblue=12,pink=13,lightcyan=14
return f"\033[{(30+col) if col<8 else (90-8+col)}m"
if CLI.NO_COLOR:
return ""
else:
return f"\033[{(30+col) if col<8 else (90-8+col)}m"

def bg4(col):
# black=0,red=1,green=2,orange=3,blue=4,purple=5,cyan=6,lightgrey=7
return f"\033[{40+col}m"
if CLI.NO_COLOR:
return ""
else:
return f"\033[{40+col}m"

# 8bit xterm colors
def fg8(col):
return f"\033[38;5;{col}m"
if CLI.NO_COLOR:
return ""
else:
return f"\033[38;5;{col}m"

def bg8(col):
return f"\033[48;5;{col}m"
if CLI.NO_COLOR:
return ""
else:
return f"\033[48;5;{col}m"

def write(*text):
for t in text:
Expand Down

0 comments on commit 8baf277

Please sign in to comment.